/*
* @Author: sam
* @Date:   2017-10-13 11:04:35
* @Last Modified by:   sam
* @Last Modified time: 2017-10-24 11:47:04
*/
(function(win){
	var TypeBox = function(id){
		this.status = "shi";
		this.list = ["shi","xian","zhen","cun","one"];
		this.init.call(this,id);
	};
	TypeBox.prototype = {
		init : function(id){//初始化
			this.id = id;
			this.domSelector = {
				'shi' : '.shi',
				'xian' : '.xian',
				'zhen' : '.zhen',
				'cun' : '.cun',
				'one' : '.cun'
			};
			this.dom = document.getElementById(this.id);
			this.getDom();
			return this;
		},
		getDom : function(){
			this.doms = {};
			for(var key in this.domSelector){
				this.doms[key] = this.dom.querySelector(this.domSelector[key]);
			}
		},
		next : function(){
			var index = this.list.indexOf(this.status);
			if(index !== this.list.length - 1){
				this.doms[this.status].classList.remove('active');
				this.status = this.list[index+1];
				this.doms[this.status].classList.add('active');
				//console.log(this.status);
				return true;
			}
			return false;
		},
		prev : function(){
			var index = this.list.indexOf(this.status);
			if(index !== 0){
				this.doms[this.status].classList.remove('active');
				this.status = this.list[index-1];
				this.doms[this.status].classList.add('active');
				//console.log(this.status);
				return true;
			}
			return false;
		},
		first : function(){
			this.doms[this.status].classList.remove('active');
			this.status = this.list[0];
			this.doms[this.status].classList.add('active');
		},
		last : function(){
			this.doms[this.status].classList.remove('active');
			this.status = this.list[this.list.length - 1];
			this.doms[this.status].classList.add('active');
		}
	};
	win.Class = win.Class || {};
	win.Class.TypeBox = TypeBox;
})(window);